package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    // 注入业务层
    @Autowired
    private VehicleService vehicleService;

    /**
     * 显示车辆全部的基本信息
     *
     * @param vehicleQuery
     * @return
     */
    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询所有车辆管理信息={}", vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    /**
     * 新增车辆信息
     *
     * @param vehicleSaveParam
     * @return
     */
    @PostMapping("save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("保存车辆信息={}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    /**
     * 删除车辆信息
     *
     * @param vehicleId
     * @return
     */
    @PostMapping("delete/{vehicleId}")
    public JsonResult updateVehicle(@PathVariable Long vehicleId) {
        log.debug("删除车辆信息的={}", vehicleId);
        vehicleService.deleteVehicle(vehicleId);
        return JsonResult.ok();
    }

    /**
     * 移除/解绑电子围栏
     * @param vehicleId
     * @return
     */
    @PostMapping("unbind/{vehicleId}")
    public JsonResult unbindVehicle(@PathVariable Long vehicleId){
        log.debug("移除/解绑电子围栏={}",vehicleId);
        vehicleService.unbindVehicle(vehicleId);
        return JsonResult.ok();
    }

    /**
     * 绑定车辆
     * @param geofenceId
     * @param vehicleId
     * @return
     */
    @PostMapping("bind/{geofenceId}/{vehicleId}")
    public JsonResult bindVehicle(@PathVariable Long geofenceId,@PathVariable Long vehicleId){
        log.debug("绑定车辆={}",geofenceId);
        log.debug("绑定车辆={}",vehicleId);
        vehicleService.bindVehicle(geofenceId,vehicleId);
        return JsonResult.ok();
    }
}
